
:: change encoding to UTF - 8
chcp 65001
:: show current dir
echo curdir:%cd%  
set p_work=%cd%
:: show bat ,include \
:: echo BAT dir:%~dp0 
:: write file
cd %~dp0 
:: vscode close
:: start %SystemRoot%\system32\cmd.exe /c TASKKILL /F /FI "IMAGENAME eq code*
:: update
@echo off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if exist "bat_protect.txt" (
    echo "bat is run protected,"
    exit
)
echo "bat is protects" > bat_protect.txt
:: 以下为脚本核心逻辑
echo "start bat"

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 切换目录 
cd ../
:: 输出日志
echo ---                          >> readme.md
echo ### %date:~3,10% %time:~0,5% >> readme.md
echo *                            >> readme.md
echo *                            >> readme.md
start code readme.md &
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 同步特定的文件到ubuntu目录下
:: 获取当前工作目录
for /f "tokens=*" %%a in ('cd') do set "currentDir=%%a"
:: 提取最后一个文件夹名称
for %%a in ("%currentDir%") do set "folderName=%%~nxa"
:: 获取ubuntu目录
set srcWindow=%folderName%
set dstUbuntu=%folderName:window=ubuntu%
:: 切换到上级目录
cd ..
:: 拷贝对应的src文件夹以及关联的源文件
:: 创建目标目录（如果不存在）
if not exist "%dstUbuntu%" mkdir "%dstUbuntu%"

:: 复制所有源码
xcopy "%srcWindow%\src\*" "%dstUbuntu%\src\" /E /I /H /Y
xcopy "%srcWindow%\public_resource\*" "%dstUbuntu%\public_resource\" /E /I /H /Y
xcopy "%srcWindow%\qt_bat\*" "%dstUbuntu%\qt_bat\" /E /I /H /Y

:: 复制顶层的一些文件
xcopy "%srcWindow%\main.cpp"       "%dstUbuntu%\main.cpp" /E /I /H /Y
xcopy "%srcWindow%\mainwindow.cpp" "%dstUbuntu%\mainwindow.cpp" /E /I /H /Y
xcopy "%srcWindow%\mainwindow.h"   "%dstUbuntu%\mainwindow.h" /E /I /H /Y
xcopy "%srcWindow%\ui_mainwindow.h"   "%dstUbuntu%\ui_mainwindow.h" /E /I /H /Y
xcopy "%srcWindow%\mainwindow.ui"  "%dstUbuntu%\mainwindow.ui" /E /I /H /Y
xcopy "%srcWindow%\*.pro" "%dstUbuntu%\" /E /I /H /Y

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 延时释放运行
echo curdir:%cd% &
ping -n 12 127.0.0.1 > nul
cd %~dp0 
del "bat_protect.txt"


:: 调试开关
:: pause


